package Year22_Month06.day17;

public class 左叶子之和_递归写法 {
    int val;
    public int sumOfLeftLeaves(TreeNode root) {
        solve(root);
        return val;
    }

    public void solve(TreeNode root){
        //如果当前节点为null就直接返回
        if(root == null) return;
        //如果是左叶子节点就加到val上去
        if(root.left != null && root.left.left == null && root.left.right == null) val += root.left.val;
        //递归调用左右子树
        solve(root.left);
        solve(root.right);
    }
}
